$(function () {
    var datagrip = $("#datagrip");
    var emp_dialog = $("#emp_dialog");
    var emp_form = $("#emp_form");

    $("#member_datagrid").datagrid({
        url:'/memberInfo/query.do',
        fit:true,
        fitColumns:true,
        striped:true,
        toolbar:'#member',
        pagination: true,
        singleSelect:true,

        rownumbers:true,

        columns:[
            [
                {field:'name',title:'会员姓名',align:'center',width:100},
                {field:'cardnumber',title:'会员卡号',align:'center',width:100},
                {field:'tel',title:'电话号码',align:'center',width:100},
                {field:'rankId',title:'会员等级',align:'center',width:100},
                {field:'balance',title:'会员余额',align:'center',width:100},
            ]
        ],
        onClickRow:function (index, row) {
            $("#name").val(row.name);
            $("#tel").val(row.tel);
        }
    });

    $("#message_datagrid").datagrid({
        url:'/dataItems/selectAll.do',
        fit:true,
        fitColumns:true,
        striped:true,
        queryParams: {
            page: 1,
            rows: 100
        },
        columns:[
            [
                {field:'name',title:'信息分类',align:'center',width:100},
                {field:'intro',title:'信息内容',align:'center',width:100}
            ]
        ],
        onClickRow:function (index, row) {
            $("#content").val(row.intro);
            $("#message_dialog").dialog("close");
        }
    });
    $("#messageHistory_datagrid").datagrid({
        url:'/messageHistory/selectAll.do',
        fit:true,
        fitColumns:true,
        striped:true,
        queryParams: {
            page: 1,
            rows: 100
        },
        columns:[
            [
                {field:'name',title:'会员名字',align:'center',width:100},
                {field:'tel',title:'电话',align:'center',width:100},
                {field:'intro',title:'信息内容',align:'center',width:100},
                {field:'date',title:'发送时间',align:'center',width:100}
            ]
        ],
    });

    emp_dialog.dialog({
        width:800,
        height:400,
        buttons:'#form_btn',
        closed:true
    })

    $("#message_dialog").dialog({
        width:800,
        height:300,
        closed:true
    });
    $("#messageHistory_dialog").dialog({
        width:800,
        height:300,
        closed:true
    })

    var methodObj = {
        /*高级查询*/
        query: function () {
            var keyword=  $("input[name='keyword']").val();
            console.log(keyword);
           $("#member_datagrid").datagrid("load",{"keyword":keyword});
        },



        reload:function() {
            emp_datagrid.datagrid('reload');
        },
        save:function() {
            emp_form.form("submit",{
                url:'/employee/saveOrUpdate.do',
                onSubmit:function (param) {
                    var ids = $("#role_combobox").combobox('getValues')
                    for(var i = 0; i< ids.length; i++){
                        param["roles["+i+"].id"] = ids[i];
                    }
                },
                success:function (data) {
                    console.log(data);
                    data = $.parseJSON(data);
                    if(data.success){
                        $.messager.alert("温馨提示",data.msg,'info',function () {
                            methodObj['cancel']();
                            methodObj['reload']();
                        })
                    }else{
                        $.messager.alert("温馨提示",data.msg,'warning')
                    }
                }
            })
        },
        cancel:function () {
            emp_dialog.dialog('close')
        },


    }

    $("a[data-cmd]").click(function () {
        var methodName = $(this).data("cmd");
        methodObj[methodName]();
    })
})


function checkMessage(){
    $("#message_dialog").dialog('open');
    $("#message_dialog").dialog('setTitle','选择信息');

}
function sendOne() {
    var name =$("#name").val();
    $.post("/messageHistory/save.do",$("#send_form").serialize(),function(data){
        if(data.success){
            $.messager.alert("温馨提示","发送成功"+name+"会员!",'info',function () {
                $("#messageHistory_datagrid").datagrid('reload');
                window.location.reload();
            })
        }else{
            $.messager.alert("温馨提示",data.msg,'warning')
        }
    });
}
function messageHistory(){
    $("#messageHistory_dialog").dialog('open');
    $("#messageHistory_dialog").dialog('setTitle','会员信息历史记录');

}
